package biz.inspeed.test.mina.heart;

import java.net.InetSocketAddress;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.future.CloseFuture;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketConnector;

public class MinaClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		NioSocketConnector connector = new NioSocketConnector();

		DefaultIoFilterChainBuilder chain = connector.getFilterChain();
		ProtocolCodecFilter filter = new ProtocolCodecFilter(
				new ObjectSerializationCodecFactory());
		chain.addLast("objectFilter", filter);
		connector.setHandler(new MinaClientIoHandler());
		connector.setConnectTimeoutCheckInterval(1);
		ConnectFuture connectFuture = connector.connect(new InetSocketAddress(
				"127.0.0.1", 0xbeef));
		connectFuture.awaitUninterruptibly();
		CloseFuture closeFuture = connectFuture.getSession().getCloseFuture();
		closeFuture.awaitUninterruptibly();
		connector.dispose();
	}

}
